home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Source / GNU / emacs / src / emacs.c < prev    next >
C/C++ Source or Header  |  1992-10-16  |  19KB  |  780 lines

  1. /* Fully extensible Emacs, running on Unix, intended for GNU.
  2.    Copyright (C) 1985, 1986, 1987, 1990 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This must precede sys/signal.h on certain machines.  */
  22. #include <sys/types.h>
  23. #include <signal.h>
  24. #include <errno.h>
  25.  
  26. #include "config.h"
  27. #ifdef NULL
  28. #undef NULL
  29. #endif
  30. #include "lisp.h"
  31. #undef NULL
  32. #include "commands.h"
  33.  
  34. /* Get FIONREAD, if it is available,
  35.    just to help decide whether SIGIO should be defined.  */
  36. #ifdef USG
  37. #include <termio.h>
  38. #include <fcntl.h>
  39. #else /* not USG */
  40. #ifndef VMS
  41. #include <sys/ioctl.h>
  42. #endif /* not VMS */
  43. #endif /* not USG */
  44.  
  45. /* Allow m- file to inhibit use of FIONREAD.  */
  46. #ifdef BROKEN_FIONREAD
  47. #undef FIONREAD
  48. #endif
  49.  
  50. /* We are unable to use interrupts if FIONREAD is not available,
  51.    so flush SIGIO so we won't try. */
  52. #ifndef FIONREAD
  53. #ifdef SIGIO
  54. #undef SIGIO
  55. #endif
  56. #endif
  57.  
  58. #include <stdio.h>
  59. #include <sys/file.h>
  60.  
  61. #ifdef VMS
  62. #include <ssdef.h>
  63. #endif
  64.  
  65. #if 0 /* fcntl.h was included above.  */
  66. #ifdef USG5
  67. #include <fcntl.h>
  68. #endif
  69. #endif
  70.  
  71. #ifdef BSD
  72. #include <sys/ioctl.h>
  73. #endif
  74.  
  75. #ifdef APOLLO
  76. #ifndef APOLLO_SR10
  77. #include <default_acl.h>
  78. #endif
  79. #endif
  80.  
  81. #ifndef O_RDWR
  82. #define O_RDWR 2
  83. #endif
  84.  
  85. #define PRIO_PROCESS 0
  86.  
  87. /* Command line args from shell, as list of strings */
  88. Lisp_Object Vcommand_line_args;
  89.  
  90. /* Hook run by `kill-emacs' before it does really anything.  */
  91. Lisp_Object Vkill_emacs_hook;
  92.  
  93. /* Set nonzero after Emacs has started up the first time.
  94.   Prevents reinitialization of the Lisp world and keymaps
  95.   on subsequent starts.  */
  96. int initialized;
  97.  
  98. /* Variable whose value is symbol giving operating system type */
  99. Lisp_Object Vsystem_type;
  100.   
  101. /* If non-zero, emacs should not attempt to use an window-specific code,
  102.    but instead should use the virtual terminal under which it was started */
  103. int inhibit_window_system;
  104.  
  105. #ifdef HAVE_X_WINDOWS
  106. /* If -d option is used, this variable points to the name of
  107.    the display to use.  */
  108. char *alternate_display;
  109. char **xargv;
  110. int xargc;
  111. #endif /* HAVE_X_WINDOWS */
  112.  
  113. #ifdef USG_SHARED_LIBRARIES
  114. /* If nonzero, this is the place to put the end of the writable segment
  115.    at startup.  */
  116.  
  117. unsigned int bss_end = 0;
  118. #endif
  119.  
  120. /* Nonzero means running Emacs without interactive terminal.  */
  121.  
  122. int noninteractive;
  123.  
  124. /* Value of Lisp variable `noninteractive'.
  125.    Normally same as C variable `noninteractive'
  126.    but nothing terrible happens if user sets this one.  */
  127.  
  128. int noninteractive1;
  129.  
  130. /* Signal code for the fatal signal that was received */
  131. int fatal_error_code;
  132.  
  133. /* Nonzero if handling a fatal error already */
  134. int fatal_error_in_progress;
  135.  
  136. /* Handle bus errors, illegal instruction, etc. */
  137. fatal_error_signal (sig)
  138.      int sig;
  139. {
  140. #ifdef BSD
  141.   int tpgrp;
  142. #endif /* BSD */
  143.  
  144.   fatal_error_code = sig;
  145.   signal (sig, SIG_DFL);
  146.  
  147.   /* If fatal error occurs in code below, avoid infinite recursion.  */
  148.   if (fatal_error_in_progress)
  149.     kill (getpid (), fatal_error_code);
  150.  
  151.   fatal_error_in_progress = 1;
  152.  
  153.   /* If we are controlling the terminal, reset terminal modes */
  154. #ifdef BSD
  155.   if (ioctl(0, TIOCGPGRP, &tpgrp) == 0
  156.       && tpgrp == getpgrp (0))
  157. #endif /* BSD */
  158.     {
  159.       reset_sys_modes ();
  160.       if (sig != SIGTERM)
  161.     fprintf (stderr, "Fatal error (%d).", sig);
  162.     }
  163.  
  164.   /* Clean up */
  165. #ifdef subprocesses
  166.   kill_buffer_processes (Qnil);
  167. #endif
  168.   Fdo_auto_save (Qt);
  169.  
  170. #ifdef CLASH_DETECTION
  171.   unlock_all_files ();
  172. #endif /* CLASH_DETECTION */
  173.  
  174. #ifdef VMS
  175.   kill_vms_processes ();
  176.   LIB$STOP (SS$_ABORT);
  177. #else
  178.   /* Signal the same code; this time it will really be fatal.  */
  179.   kill (getpid (), fatal_error_code);
  180. #endif /* not VMS */
  181. }
  182.  
  183. /* Code for dealing with Lisp access to the Unix command line */
  184.  
  185. static
  186. init_cmdargs (argc, argv, skip_args)
  187.      int argc;
  188.      char **argv;
  189.      int skip_args;
  190. {
  191.   register int i;
  192.  
  193.   Vcommand_line_args = Qnil;
  194.  
  195.   for (i = argc - 1; i >= 0; i--)
  196.     {
  197.       if (i == 0 || i > skip_args)
  198.     Vcommand_line_args
  199.       = Fcons (build_string (argv[i]), Vcommand_line_args);
  200.     }
  201. }
  202.  
  203. #ifdef VMS
  204. #ifdef LINK_CRTL_SHARE
  205. #ifdef SHAREABLE_LIB_BUG
  206. #ifdef __GNUC__
  207. #define    environ $$PsectAttributes_NOSHR$$environ
  208. extern char **environ;
  209. #else
  210. extern noshare char **environ;
  211. #endif
  212. #endif /* SHAREABLE_LIB_BUG */
  213. #endif /* LINK_CRTL_SHARE */
  214. #endif /* VMS */
  215.  
  216. /* We don't include crtbegin.o and crtend.o in the link,
  217.    so these functions and variables might be missed.
  218.    Provide dummy definitions to avoid error.
  219.    (We don't have any real constructors or destructors.)  */
  220. #ifdef __GNUC__
  221. #ifndef ORDINARY_LINK
  222. __do_clobal_ctors ()
  223. {}
  224. __do_clobal_ctors_aux ()
  225. {}
  226. __do_global_dtors ()
  227. {}
  228. char * __CTOR_LIST__[2] = { (char *) (-1), 0 };
  229. char * __DTOR_LIST__[2] = { (char *) (-1), 0 };
  230. __main ()
  231. {}
  232. #endif /* not ORDINARY_LINK */
  233. #endif /* __GNUC__ */
  234.  
  235. /* ARGSUSED */
  236. main (argc, argv, envp)
  237.      int argc;
  238.      char **argv;
  239.      char **envp;
  240. {
  241.   int skip_args = 0;
  242.   extern int errno;
  243.   extern void malloc_warning ();
  244.  
  245. /* Map in shared memory, if we are using that.  */
  246. #ifdef HAVE_SHM
  247.   if (argc > 1 && !strcmp (argv[1], "-nl"))
  248.     {
  249.       map_in_data (0);
  250.       /* The shared memory was just restored, which clobbered this.  */
  251.       skip_args = 1;
  252.     }
  253.   else
  254.     {
  255.       map_in_data (1);
  256.       /* The shared memory was just restored, which clobbered this.  */
  257.       skip_args = 0;
  258.     }
  259. #endif
  260.  
  261. #ifdef VMS
  262.   /* If -map specified, map the data file in */
  263.   if (argc > 2 && ! strcmp (argv[1], "-map"))
  264.     {
  265.       skip_args = 2;
  266.       mapin_data (argv[2]);
  267.     }
  268.  
  269. #ifdef LINK_CRTL_SHARE
  270. #ifdef SHAREABLE_LIB_BUG
  271.   /* Bletcherous shared libraries! */
  272.   if (!stdin)
  273.     stdin = fdopen (0, "r");
  274.   if (!stdout)
  275.     stdout = fdopen (1, "w");
  276.   if (!stderr)
  277.     stderr = fdopen (2, "w");
  278.   if (!environ)
  279.     environ = envp;
  280. #endif /* SHAREABLE_LIB_BUG */
  281. #endif /* LINK_CRTL_SHARE */
  282. #endif /* VMS */
  283.  
  284. #ifdef USG_SHARED_LIBRARIES
  285.   if (bss_end)
  286.     brk (bss_end);
  287. #endif
  288.  
  289. #ifdef NeXT
  290.   extern int malloc_cookie;
  291.  
  292.   /* This helps out unexnext.c.  */
  293.   if (initialized)
  294.     if (malloc_jumpstart (malloc_cookie) != 0)
  295.       printf ("malloc jumpstart failed!\n");
  296. #endif /* NeXT */
  297.  
  298.   clearerr (stdin);
  299.  
  300. #ifdef APOLLO
  301. #ifndef APOLLO_SR10
  302.   /* If USE_DOMAIN_ACLS environment variable exists,
  303.      use ACLs rather than UNIX modes. */
  304.   if (egetenv ("USE_DOMAIN_ACLS"))
  305.     default_acl (USE_DEFACL);
  306. #endif
  307. #endif /* APOLLO */
  308.  
  309. #ifndef SYSTEM_MALLOC
  310.   /* Arrange for warnings when nearly out of space.  */
  311.   malloc_init (0, malloc_warning);
  312. #endif
  313.  
  314. #ifdef HIGHPRI
  315.   setpriority (PRIO_PROCESS, getpid (), HIGHPRI);
  316.   setuid (getuid ());
  317. #endif HIGHPRI
  318.  
  319.   inhibit_window_system = 0;
  320.  
  321. #ifdef HAVE_X_WINDOWS
  322.   xargv = argv;
  323.   xargc = argc;
  324. #endif
  325.  
  326. /* Handle the -t switch, which specifies filename to use as terminal */
  327.   if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t"))
  328.     {
  329.       skip_args += 2;
  330.       close (0);
  331.       close (1);
  332.       open (argv[skip_args], O_RDWR, 2 );
  333.       dup (0);
  334.       fprintf (stderr, "Using %s\n", argv[skip_args]);
  335. #ifdef HAVE_X_WINDOWS
  336.       inhibit_window_system = 1;    /* -t => -nw */
  337. #endif
  338.     }
  339. #ifdef HAVE_X_WINDOWS
  340. /* Handle the -d switch, which means use a different display for X */
  341.   if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-d") ||
  342.                    !strcmp (argv[skip_args + 1], "-display")))
  343.     {
  344.       skip_args += 2;
  345.       alternate_display = argv[skip_args];
  346.     } 
  347.   else
  348.     alternate_display = 0;
  349. #endif    /* HAVE_X_WINDOWS */
  350.  
  351.   if (skip_args + 1 < argc
  352.       && (!strcmp (argv[skip_args + 1], "-nw")))
  353.     {
  354.       skip_args += 1;
  355.       inhibit_window_system = 1;
  356.     }
  357.  
  358. /* Handle the -batch switch, which means don't do interactive display.  */
  359.   noninteractive = 0;
  360.   if (skip_args + 1 < argc && !strcmp (argv[skip_args + 1], "-batch"))
  361.     {
  362.       skip_args += 1;
  363.       noninteractive = 1;
  364.     }
  365.  
  366. #ifdef POSIX_SIGNALS
  367.   init_signals ();
  368. #endif
  369.  
  370. #ifdef HAVE_TZSET
  371.   /* Reinitialize the time zone if it was initialized before dumping Emacs.  */
  372.   if (initialized)
  373.     tzset ();
  374. #endif
  375.  
  376.   if (
  377. #ifndef CANNOT_DUMP
  378.       ! noninteractive || initialized
  379. #else
  380.       1
  381. #endif
  382.       )
  383.     {
  384.       /* Don't catch these signals in batch mode if not initialized.
  385.      On some machines, this sets static data that would make
  386.      signal fail to work right when the dumped Emacs is run.  */
  387.       signal (SIGHUP, fatal_error_signal);
  388.       signal (SIGQUIT, fatal_error_signal);
  389.       signal (SIGILL, fatal_error_signal);
  390.       signal (SIGTRAP, fatal_error_signal);
  391.       signal (SIGIOT, fatal_error_signal);
  392. #ifdef SIGEMT
  393.       signal (SIGEMT, fatal_error_signal);
  394. #endif
  395.       signal (SIGFPE, fatal_error_signal);
  396.       signal (SIGBUS, fatal_error_signal);
  397.       signal (SIGSEGV, fatal_error_signal);
  398.       signal (SIGSYS, fatal_error_signal);
  399.       signal (SIGTERM, fatal_error_signal);
  400. #ifdef SIGXCPU
  401.       signal (SIGXCPU, fatal_error_signal);
  402. #endif
  403. #ifdef SIGXFSZ
  404.       signal (SIGXFSZ, fatal_error_signal);
  405. #endif SIGXFSZ
  406.  
  407. #ifdef AIX
  408.       /* This used to run fatal_error_signal,
  409.      but it isn't fatal.  There's nothing Emacs can usefully do.
  410.      Might as well let the system kill us if it insists.  */
  411.       signal (SIGDANGER, SIG_IGN);
  412.       signal (20, fatal_error_signal);
  413.       signal (21, fatal_error_signal);
  414.       signal (22, fatal_error_signal);
  415.       signal (23, fatal_error_signal);
  416.       signal (24, fatal_error_signal);
  417. #ifdef SIGIO
  418.       signal (SIGAIO, fatal_error_signal);
  419.       signal (SIGPTY, fatal_error_signal);
  420. #endif
  421. #ifdef SIGURG
  422.       /* Note that SIGIOINT is the same as SIGIO on some machines,
  423.      and the same as SIGURG on others.  It seems ore reliable to use the
  424.      name with a uniform meaning.  */
  425.       signal (SIGURG, fatal_error_signal);
  426. #endif
  427.       signal (SIGGRANT, fatal_error_signal);
  428.       signal (SIGRETRACT, fatal_error_signal);
  429.       signal (SIGSOUND, fatal_error_signal);
  430.       signal (SIGMSG, fatal_error_signal);
  431. #endif /* AIX */
  432.     }
  433.  
  434.   noninteractive1 = noninteractive;
  435.  
  436. /* Perform basic initializations (not merely interning symbols) */
  437.  
  438.   if (!initialized)
  439.     {
  440.       init_alloc_once ();
  441.       init_obarray ();
  442.       init_eval_once ();
  443.       init_syntax_once ();    /* Create standard syntax table.  */
  444.               /* Must be done before init_buffer */
  445.       init_buffer_once ();    /* Create buffer table and some buffers */
  446.       init_minibuf_once ();    /* Create list of minibuffers */
  447.                   /* Must precede init_window_once */
  448.       init_window_once ();    /* Init the window system */
  449.     }
  450.  
  451.   init_alloc ();
  452. #ifdef MAINTAIN_ENVIRONMENT
  453.   init_environ ();
  454. #endif
  455.   init_eval ();
  456.   init_data ();
  457.   init_read ();
  458.  
  459.   init_cmdargs (argc, argv, skip_args);    /* Create list Vcommand_line_args */
  460.   init_buffer ();    /* Init default directory of main buffer */
  461.   if (!noninteractive)
  462.     {
  463. #ifdef VMS
  464.       init_vms_input ();/* init_display calls get_screen_size, that needs this */
  465. #endif /* VMS */
  466.       init_display ();    /* Determine terminal type.  init_sys_modes uses results */
  467.     }
  468.   init_keyboard ();    /* This too must precede init_sys_modes */
  469.   init_callproc ();    /* And this too. */
  470.   init_sys_modes ();    /* Init system terminal modes (RAW or CBREAK, etc.) */
  471.   init_xdisp ();
  472.   init_macros ();
  473.   init_editfns ();
  474. #ifdef VMS
  475.   init_vmsfns ();
  476. #endif /* VMS */
  477. #ifdef subprocesses
  478.   init_process ();
  479. #endif /* subprocesses */
  480.  
  481. /* Intern the names of all standard functions and variables; define standard keys */
  482.  
  483.   if (!initialized)
  484.     {
  485.       /* The basic levels of Lisp must come first */
  486.       /* And data must come first of all
  487.      for the sake of symbols like error-message */
  488.       syms_of_data ();
  489.       syms_of_alloc ();
  490. #ifdef MAINTAIN_ENVIRONMENT
  491.       syms_of_environ ();
  492. #endif MAINTAIN_ENVIRONMENT
  493.       syms_of_read ();
  494.       syms_of_print ();
  495.       syms_of_eval ();
  496.       syms_of_fns ();
  497.  
  498.       syms_of_abbrev ();
  499.       syms_of_buffer ();
  500.       syms_of_bytecode ();
  501.       syms_of_callint ();
  502.       syms_of_casefiddle ();
  503.       syms_of_callproc ();
  504.       syms_of_cmds ();
  505. #ifndef NO_DIR_LIBRARY
  506.       syms_of_dired ();
  507. #endif /* not NO_DIR_LIBRARY */
  508.       syms_of_display ();
  509.       syms_of_doc ();
  510.       syms_of_editfns ();
  511.       syms_of_emacs ();
  512.       syms_of_fileio ();
  513. #ifdef CLASH_DETECTION
  514.       syms_of_filelock ();
  515. #endif /* CLASH_DETECTION */
  516.       syms_of_indent ();
  517.       syms_of_keyboard ();
  518.       syms_of_keymap ();
  519.       syms_of_macros ();
  520.       syms_of_marker ();
  521.       syms_of_minibuf ();
  522.       syms_of_mocklisp ();
  523. #ifdef subprocesses
  524.       syms_of_process ();
  525. #endif /* subprocesses */
  526.       syms_of_search ();
  527.       syms_of_syntax ();
  528.       syms_of_undo ();
  529.       syms_of_window ();
  530.       syms_of_xdisp ();
  531. #ifdef HAVE_X_WINDOWS
  532.       syms_of_xfns ();
  533. #ifdef HAVE_X_MENU
  534.       syms_of_xmenu ();
  535. #endif /* HAVE_X_MENU */
  536. #endif /* HAVE_X_WINDOWS */
  537.  
  538. #ifdef SYMS_SYSTEM
  539.       SYMS_SYSTEM;
  540. #endif
  541.  
  542. #ifdef SYMS_MACHINE
  543.       SYMS_MACHINE;
  544. #endif
  545.  
  546.       keys_of_casefiddle ();
  547.       keys_of_cmds ();
  548.       keys_of_buffer ();
  549.       keys_of_keyboard ();
  550.       keys_of_keymap ();
  551.       keys_of_macros ();
  552.       keys_of_minibuf ();
  553.       keys_of_window ();
  554.     }
  555.  
  556.   if (!initialized)
  557.     {
  558.       /* Handle -l loadup-and-dump, args passed by Makefile. */
  559.       if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l"))
  560.     Vtop_level = Fcons (intern ("load"),
  561.                 Fcons (build_string (argv[2 + skip_args]), Qnil));
  562. #ifdef CANNOT_DUMP
  563.       /* Unless next switch is -nl, load "loadup.el" first thing.  */
  564.       if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl")))
  565.     Vtop_level = Fcons (intern ("load"),
  566.                 Fcons (build_string ("loadup.el"), Qnil));
  567. #endif /* CANNOT_DUMP */
  568.     }
  569.  
  570.   initialized = 1;
  571.  
  572.   /* Enter editor command loop.  This never returns.  */
  573.   Frecursive_edit ();
  574.   /* NOTREACHED */
  575. }
  576.  
  577. DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
  578.   "Exit the Emacs job and kill it.  ARG means no query.\n\
  579. If emacs is running noninteractively and ARG is an integer,\n\
  580. return ARG as the exit program code.")
  581.   (arg)
  582.      Lisp_Object arg;
  583. {
  584.   Lisp_Object answer;
  585.   int i;
  586.   struct gcpro gcpro1;
  587.  
  588.   GCPRO1 (arg);
  589.  
  590.   if (!EQ (Vkill_emacs_hook, Qnil))
  591.     call0 (Vkill_emacs_hook);
  592.  
  593.   if (feof (stdin))
  594.     arg = Qt;
  595.  
  596. #ifdef subprocesses
  597.   kill_buffer_processes (Qnil);
  598. #endif /* subprocesses */
  599.  
  600. #ifdef VMS
  601.   kill_vms_processes ();
  602. #endif /* VMS */
  603.  
  604.   Fdo_auto_save (Qt);
  605.  
  606. #ifdef CLASH_DETECTION
  607.   unlock_all_files ();
  608. #endif /* CLASH_DETECTION */
  609.  
  610.   fflush (stdout);
  611.   reset_sys_modes ();
  612.   UNGCPRO;
  613.  
  614. /* Is it really necessary to do this deassign
  615.    when we are going to exit anyway?  */
  616. /* #ifdef VMS
  617.   stop_vms_input ();
  618.  #endif  */
  619.   stuff_buffered_input (arg);
  620. #ifdef SIGIO
  621.   /* There is a tendency for a SIGIO signal to arrive within exit,
  622.      and cause a SIGHUP because the input descriptor is already closed.  */
  623.   unrequest_sigio ();
  624.   signal (SIGIO, SIG_IGN);
  625. #endif
  626.   exit ((XTYPE (arg) == Lisp_Int) ? XINT (arg)
  627. #ifdef VMS
  628.     : 1
  629. #else
  630.     : 0
  631. #endif
  632.     );
  633.   /* NOTREACHED */
  634. }
  635.  
  636. #ifndef CANNOT_DUMP
  637. /* Nothing like this can be implemented on an Apollo.
  638.    What a loss!  */
  639.  
  640. #ifdef HAVE_SHM
  641.  
  642. DEFUN ("dump-emacs-data", Fdump_emacs_data, Sdump_emacs_data, 1, 1, 0,
  643.   "Dump current state of Emacs into data file FILENAME.\n\
  644. This function exists on systems that use HAVE_SHM.")
  645.   (intoname)
  646.      Lisp_Object intoname;
  647. {
  648.   extern int my_edata;
  649.   Lisp_Object tem;
  650.   extern void malloc_warning ();
  651.  
  652.   CHECK_STRING (intoname, 0);
  653.   intoname = Fexpand_file_name (intoname, Qnil);
  654.  
  655.   tem = Vpurify_flag;
  656.   Vpurify_flag = Qnil;
  657.  
  658.   fflush (stdout);
  659.   /* Tell malloc where start of impure now is */
  660.   /* Also arrange for warnings when nearly out of space.  */
  661. #ifndef SYSTEM_MALLOC
  662.   malloc_init (&my_edata, malloc_warning);
  663. #endif
  664.   map_out_data (XSTRING (intoname)->data);
  665.  
  666.   Vpurify_flag = tem;
  667.  
  668.   return Qnil;
  669. }
  670.  
  671. #else /* not HAVE_SHM */
  672.  
  673. DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0,
  674.   "Dump current state of Emacs into executable file FILENAME.\n\
  675. Take symbols from SYMFILE (presumably the file you executed to run Emacs).")
  676.   (intoname, symname)
  677.      Lisp_Object intoname, symname;
  678. {
  679.   extern int my_edata;
  680.   Lisp_Object tem;
  681.   extern void malloc_warning ();
  682.  
  683.   CHECK_STRING (intoname, 0);
  684.   intoname = Fexpand_file_name (intoname, Qnil);
  685.   if (!EQ (symname, Qnil))
  686.     {
  687.       CHECK_STRING (symname, 0);
  688.       if (XSTRING (symname)->size)
  689.     symname = Fexpand_file_name (symname, Qnil);
  690.     }
  691.  
  692.   tem = Vpurify_flag;
  693.   Vpurify_flag = Qnil;
  694.  
  695.   fflush (stdout);
  696. #ifdef VMS
  697.   mapout_data (XSTRING (intoname)->data);
  698. #else
  699.   /* Tell malloc where start of impure now is */
  700.   /* Also arrange for warnings when nearly out of space.  */
  701. #ifndef SYSTEM_MALLOC
  702.   malloc_init (&my_edata, malloc_warning);
  703. #endif
  704.   unexec (XSTRING (intoname)->data,
  705.       !EQ (symname, Qnil) ? XSTRING (symname)->data : 0, &my_edata, 0, 0);
  706. #endif /* not VMS */
  707.  
  708.   Vpurify_flag = tem;
  709.  
  710.   return Qnil;
  711. }
  712.  
  713. #endif /* not HAVE_SHM */
  714.  
  715. #endif /* not CANNOT_DUMP */
  716.  
  717. #ifdef VMS
  718. #define SEPCHAR ','
  719. #else
  720. #define SEPCHAR ':'
  721. #endif
  722.  
  723. Lisp_Object
  724. decode_env_path (evarname, defalt)
  725.      char *evarname, *defalt;
  726. {
  727.   register char *path, *p;
  728.   extern char *index ();
  729.  
  730.   Lisp_Object lpath;
  731.  
  732.   if (evarname != 0)
  733.     path = (char *) egetenv (evarname);
  734.   else
  735.     path = 0;
  736.   if (!path)
  737.     path = defalt;
  738.   lpath = Qnil;
  739.   while (1)
  740.     {
  741.       p = index (path, SEPCHAR);
  742.       if (!p) p = path + strlen (path);
  743.       lpath = Fcons (p - path ? make_string (path, p - path) : Qnil,
  744.              lpath);
  745.       if (*p)
  746.     path = p + 1;
  747.       else
  748.     break;
  749.     }
  750.   return Fnreverse (lpath);
  751. }
  752.  
  753. syms_of_emacs ()
  754. {
  755. #ifndef CANNOT_DUMP
  756. #ifdef HAVE_SHM
  757.   defsubr (&Sdump_emacs_data);
  758. #else
  759.   defsubr (&Sdump_emacs);
  760. #endif
  761. #endif /* not CANNOT_DUMP */
  762.  
  763.   defsubr (&Skill_emacs);
  764.  
  765.   DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
  766.     "Args passed by shell to Emacs, as a list of strings.");
  767.  
  768.   DEFVAR_LISP ("system-type", &Vsystem_type,
  769.     "Symbol indicating type of operating system you are using.");
  770.   Vsystem_type = intern (SYSTEM_TYPE);
  771.  
  772.   DEFVAR_BOOL ("noninteractive", &noninteractive1,
  773.     "Non-nil means Emacs is running without interactive terminal.");
  774.  
  775.   Vkill_emacs_hook = Qnil;
  776.  
  777.   DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook,
  778.     "Function called, if non-nil, whenever kill-emacs is called.");
  779. }
  780.